package com.zrrd.jt_admin.common.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ZhangYK
 * @version 8.0
 * @title MybatisPlusConfig
 * @description
 * @create 2024/6/17 21:24
 */
@Configuration
@MapperScan("com.zrrd.jt_admin.*.mapper")
public class MybatisPlusConfig {
    /**
     * 添加分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {

        //创建 MybatisPlus拦截器对象
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //添加某个内置拦截器
        //如果配置多个插件,切记分页最后添加
        //PaginationInnerInterceptor对象，分页内部拦截器对象
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));

        //添加乐观锁拦截器
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());


        return interceptor;
    }
}
